package com.example.foo.user.dao;

import org.apache.commons.lang3.StringUtils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.core.PageResult;
import com.example.core.Pageable;
import com.example.foo.user.model.User;
import com.example.foo.user.query.UserQuery;

@org.apache.ibatis.annotations.Mapper
public interface UserDao extends com.example.core.dao.BaseDao<User, Long> {

	public default PageResult<User> findUsers(UserQuery userQuery, Pageable pageable) {
		QueryWrapper<User> queryWrapper = createQueryWithBaseIf(userQuery);
		//
		if (StringUtils.isNotEmpty(userQuery.getCellphone())) {
			queryWrapper.like("cellphone", userQuery.getCellphone());
		}
		if (StringUtils.isNotEmpty(userQuery.getName())) {
			queryWrapper.like("name", userQuery.getName());
		}
		if (StringUtils.isNotEmpty(userQuery.getWxUnionid())) {
			queryWrapper.eq("wx_unionid", userQuery.getWxUnionid());
		}
		return findPages(queryWrapper, pageable);
	}

}
